// pages/history/history.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    pic: "",
    // 设置开始的位置
    startX: 0,
    startY: 0,
  },

  Decoder:function(str){
    var res="";
    for(var i=0;i<str.length;i++){
      if(str[i]=='#'){
        res+='&';
      }else{
        res+=str[i];
      }
    }
    return res;
  },

  onLoad: function () {
    var that=this
    wx.request({
      url: app.globalData.urlHome + '/user/getUserCard',
      data: {
        "openid":app.globalData.openid
      },
      header: {
        "accept": "*/*",
        "content-type": "application/json",
        "Authorization": app.globalData.token
      },
      method: "GET",
      success(r) {
    //    console.log(r.data);
        var len = r.data.length;

        if(len==0){
          that.setData({
            image:"/resources/images/myPage/kong.png",
            text:"这里空空如也，快去附近看看物语吧！",
          })
          return;
        }
        
        var tem = [];
        for (var i = 1; i <= len; i++) {
          var card =r.data[i-1];
          card.id = i;
          card.isTouchMove=false;
         // console.log(card);
          tem.push(card);
        }

        that.setData({
          dataList: tem
        })
       // console.log(that.data.dataList)
      }
    })
  },

  Encoder: function (str) {
    var res = "";
    for (var i = 0; i < str.length; i++) {
      if (str[i] == '&') {
        res += '#';
      } else {
        res += str[i];
      }
    }
    return res;
  },

  onClick:function(e){
    var that = this;
    var index = e.currentTarget.dataset['index']
    console.log(index)
    wx.navigateTo({
      url: '../detail/detail?json=' + that.Encoder(JSON.stringify(this.data.dataList[index])),
    })
  }
})